<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header"><i class="fa fa-laptop"></i> 系统用户</h3>
        <ol class="breadcrumb">
            <li><i class="fa fa-home"></i><a href="index.html">系统设置</a></li>
            <li><i class="fa fa-laptop"></i>系统用户</li>
        </ol>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                新增角色
            </header>
            <div class="panel-body">
                <form class="form-horizontal " method="post" action="index.php?r=role/savedata" >
                    <div class="form-group">
                        <label class="col-sm-2 control-label">角色名称</label>
                        <div class="col-sm-10">
                            <input type="text" name="name" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-10">
                            <input type="text" name="description" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">权限</label>
                        <div class="col-sm-10">
                            <section class="panel">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th><div class="checkbox"><label>
                                                <input type="checkbox" id="ck_all" value="1">
                                                全选
                                                </label></div></th>
                                        <th>权限</th>
                                        <th>CODE</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    foreach ($menus as $menu) {
                                        ?>
                                        <tr>
                                            <td><div class="checkbox"><label>
                                                    <input type="checkbox" name="permission[]" class="ck_item"
                                                           value="<?php echo $menu['menupermission'] ?>">
                                                    </label></div></td>
                                            <td><?php echo $menu['menutext'] ?></td>
                                            <td><?php echo $menu['menupermission'] ?></td>
                                        </tr>
                                        <?php
                                        if (sizeof($menu['items']) > 0) {
                                            foreach ($menu['items'] as $item) {
                                                ?>
                                                <tr>
                                                    <td><div class="checkbox"><label>
                                                            <input type="checkbox"  name="permission[]" class="ck_item"
                                                                   value="<?php echo $item['menupermission'] ?>">
                                                            </label></div></td>
                                                    <td style="padding-left: 40px;"><?php echo $item['menutext'] ?></td>
                                                    <td><?php echo $item['menupermission'] ?></td>
                                                </tr>
                                                <?php
                                                if(sizeof($item['actions'])>0){
                                                    foreach ($item['actions'] as $action) {
                                                        ?>
                                                        <tr>
                                                            <td><div class="checkbox"><label>
                                                                    <input type="checkbox"  name="permission[]" class="ck_item"
                                                                           value="<?php echo $action['menupermission'] ?>">
                                                                    </label></div></td>
                                                            <td style="padding-left: 80px;"><?php echo $action['menutext'] ?></td>
                                                            <td><?php echo $action['menupermission'] ?></td>
                                                        </tr>
                                                        <?php
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ?>
                                    </tbody>
                                </table>
                            </section>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>
<script>
    $(function () {
        $("#menu_sysconfig").addClass("active");
        $("#menu_sysconfig .menu-arrow").removeClass("arrow_carrot-right").addClass("arrow_carrot-down");
        $("#item_sysconfig_role_module").parent("li").addClass("active");
        initPage();
    });
    function initPage() {
        $("#ck_all").click(function () {
            var ck_all_checked = $("#ck_all").attr("checked");
            if(ck_all_checked == 'checked'){
                $(".ck_item").attr("checked","true");
            }else{
                $(".ck_item").removeAttr("checked");
            }
        });
    }
</script>